<template>
  <!-- 入账提示 -->
  <div>
    <FilterTable
      ref="table"
      :columns="columns"
      columnsRef="partPartInventoryPartInventoryComponentsBookedTip"
      height="auto"
      :dataSource="dataSource"
      :onSyncTableData="tablechangeFun"
      :onColumnsChange="columns => (this.columns = columns)"
    ></FilterTable>
    <div class="btnWrap">
      <el-button size="small" @click="$emit('cancel')">取 消</el-button>
      <el-button size="small" type="primary" @click="comfirmBtnClick">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { partbuyEnterRecord } from '@/api/part/partInventory/partInventory/index.js';
import * as Util from '@/utils/index.js';

export default {
  name: 'wxll_back_part',
  props: {
    tableData: Array
  },
  data() {
    return {
      columns: this.createColumns()
      // dataSource: []
    };
  },
  computed: {
    dataSource() {
      if (this.tableData) {
        return this.tableData.map(item => {
          return item;
        });
      } else {
        return [];
      }
    }
  },
  mounted() {
    window.cgrk_booked_tip = this;
    console.log('tableData', Object.assign(this.tableData));
  },
  methods: {
    createColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库',
          // sorter: true,
          dataIndex: 'STORAGE_NAME',
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件代码',
          // sorter: true,
          dataIndex: 'PART_NO',
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件名称',
          // sorter: true,
          dataIndex: 'PART_NAME',
          filter: true,
          filterType: 'input'
        },
        {
          title: '最新进货价',
          // sorter: true,
          dataIndex: 'LATEST_PRICE',
          filter: true,
          filterType: 'number'
        },
        {
          title: '含税单价',
          // sorter: true,
          dataIndex: 'IN_PRICE_TAXED',
          filter: true,
          filterType: 'number'
        },
        {
          title: '差额',
          // sorter: true,
          dataIndex: 'BALANCE',
          filter: true,
          filterType: 'number'
        }
      ];
    },
    tablechangeFun(val) {
      val.forEach(x => {
        if (x.IN_PRICE_TAXED == null || x.IN_PRICE_TAXED == '' || x.IN_PRICE_TAXED == undefined) {
          x.IN_PRICE_TAXED = 0.0;
        }
        if (x.LATEST_PRICE == null || x.LATEST_PRICE == '' || x.LATEST_PRICE == undefined) {
          x.LATEST_PRICE = 0.0;
        }
        x.BALANCE = (Number(x.IN_PRICE_TAXED) - Number(x.LATEST_PRICE)).toFixed(2);
      });
    },
    // 确定按钮
    async comfirmBtnClick() {
      console.log('点击确定');
      this.$emit('confirm');
    }
  }
};
</script>

<style scoped>
.btnWrap {
  position: absolute;
  left: 0px;
  bottom: 0px;
  right: 0px;
  z-index: 9;
  border-top: 1px solid rgb(233, 233, 233);
  padding: 10px 20px;
  background: rgb(255, 255, 255);
  text-align: right;
}
</style>
